set.seed(1234)
loc <- unique(dta[,loc.var])
shuffle <- sample(loc,  length(loc),  replace=FALSE)  
locs.train <- shuffle[1:(round(length(shuffle)/2,0))]
locs.test <- shuffle[(round(length(shuffle)/2,0)+1):length(shuffle)]

insample.index <- dta[,loc.var] %in% locs.train
outsample.index <- dta[,loc.var] %in% locs.test

dta.test <- dta[outsample.index,]
dta.train <-dta[insample.index,]    